package com.example.android_timer;

import java.util.TimerTask;
import java.util.Date;
import java.text.SimpleDateFormat;


import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

/**
* This is a timertask because it extends the class java.util.TimerTask. This class
* will be given to the timer (java.util.Timer) as the code to be executed.
*
* @see java.util.Timer
* @see java.util.TimerTask
* @author http://www.gammelsaeter.com/
*/
public class Task extends TimerTask {
	


	private static final String TAG = "MyActivity";
	
	private String _objectName;                 // A string to output
	
	private Activity _parentAct;
	
	private int i = 1;
	
	
	
	public void SetParentActivity(Activity act){
		_parentAct = act;
	}
	
	/**
	* Constructs the object, sets the string to be output in function run()
	* @param str
	*/
	Task(String objectName) {
	this._objectName = objectName;
	this._parentAct = null;
	
	}
	
	/**
	* When the timer executes, this code is run.
	*/
	public void run() {
	//  update text view
		Log.d(TAG, "hihihi");
		
		i++;
		_parentAct.runOnUiThread(new Runnable(){
            public void run() {
        		TextView text1 = (TextView) _parentAct.findViewById(R.id.textView1);	
        		text1.setText(String.valueOf(i));
             }
			
		});

		
		
	}
}